package u17.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import u17.dao.UserMapper;
import u17.model.User;

/**
 * 玩家信息服务接口 实现
 * @author 杜延雷 
 */
@Service("userService")
public class UserServiceImpl implements UserService{
	private UserMapper userMapper;
	
	public UserMapper getUserMapper() {
		return userMapper;
	}

	@Autowired
	public void setUserMapper(UserMapper userMapper) {
		this.userMapper = userMapper;
	}

	/*
	 * 根据ID查询玩家
	 */
	@Override
	public User getUserById(Integer id) throws Exception{
		try {
			return userMapper.selectByPrimaryKey(id);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}

	/*
	 * 查询所有玩家信息
	 */
	@Override
	public List<User> getAllUser()  throws Exception{
		try {
			return userMapper.getAllUser();
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}

	/*
	 * 添加玩家
	 */
	@Override
	public int addUser(User user) throws Exception{
		return userMapper.insertSelective(user);
	}

	/*
	 * 修改玩家信息
	 */
	@Override
	public int updateUser(User user) throws Exception{
		return userMapper.updateByPrimaryKeySelective(user);
	}

	/*
	 * 删除玩家信息
	 */
	@Override
	public void deleteUser(Integer yid) throws Exception{
		userMapper.deleteByPrimaryKey(yid);
	}
	
	/*
	 * 查询分页查询玩家信息
	 */
	@Override
	public Map<String,Object> getUserPaging(User user)  throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		try {
			 map.put("total", userMapper.queryUserCount(user));
		     map.put("rows", userMapper.queryUserPager(user));
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
		return map;
	}
}
